package com.killer;

import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.view.ActionMode;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;

public class ActionModeActivity extends AppCompatActivity {

    private ActionBar actionBar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_temp);
        initActionBar();
    }

    private void initActionBar() {
        //得到ActionBar
        actionBar = getSupportActionBar();
        actionBar.setDisplayShowHomeEnabled(true);//默认是false  默认不显示显示icon/logo
        actionBar.setDisplayUseLogoEnabled(false);

       actionBar.setLogo(R.drawable.ic_action_edit);//设置logo,默认是logo优先
       actionBar.setIcon(R.drawable.ic_launcher);
       actionBar.setTitle("主标题");
        actionBar.setSubtitle("副标题");
        actionBar.setDisplayHomeAsUpEnabled(true);//设置显示返回按钮
        actionBar.setDisplayShowTitleEnabled(true);//显示/隐藏title部分
        actionBar.setDisplayHomeAsUpEnabled(true);// 设置back按钮是否可见
    }
    public void click(View view){
        startSupportActionMode(new ActionMode.Callback() {
            @Override
            public boolean onCreateActionMode(ActionMode mode, Menu menu) {
                getMenuInflater().inflate(R.menu.actionmode,menu);
                return true;
            }

            @Override
            public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
                return false;
            }

            @Override
            public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
                switch (item.getItemId()) {
                    case R.id.action_mode_1:
                        Toast.makeText(getApplicationContext(), "action_mode_1", Toast.LENGTH_SHORT).show();
                        break;
                    case R.id.action_mode_2:
                        Toast.makeText(getApplicationContext(), "action_mode_2", Toast.LENGTH_SHORT).show();

                        break;
                    case R.id.action_mode_3:
                        Toast.makeText(getApplicationContext(), "action_mode_3", Toast.LENGTH_SHORT).show();

                        break;

                    default:
                        break;
                }
                return false;
            }

            @Override
            public void onDestroyActionMode(ActionMode mode) {

            }
        });
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()){
            case android.R.id.home:
                finish();
                break;
            default:
                break;
        }
        return super.onOptionsItemSelected(item);
    }
}
